﻿using System;
using System.Threading;

namespace LDSCore
{
    public class ThreadExecutor
    {
        public static bool Execute(WaitCallback callback, object state)
        {
            try
            {
                return ThreadPool.QueueUserWorkItem(data =>
                {
                    try
                    {
                        callback(data);
                    }
                    catch (Exception ex)
                    {
                        //Execute(callback, state);
                        LogFileHelper.Record(ex);
                    }
                }, state);
            }
            catch (Exception e)
            {
                LogFileHelper.Record(e);
            }
            return false;
        }

        public static bool Execute(WaitCallback callback)
        {
            return Execute(callback, null);
        }
    }
}
